package keter.combofs.util;

/**
 * Created by gulx@neusoft.com on 2019/11/21.
 */
public class PathMakerUtil {

    public static String caculatePath(String fileName) {
        // 使用操作系统目录分隔符
        return caculatePath(fileName,java.io.File.separator);
    }

    /**
     * 计算目录生成规则：根据文件名称的哈希值取0~256的一级子目录和0~16的二级子目录
     * @param fileName
     * @return
     */
    public static String caculatePath(String fileName, String seprator) {
        int lv1 = fileName.hashCode() & 0xff;
        String lv1Str = String.valueOf(fileName.hashCode() & 0xff);
        lv1Str = PathMakerUtil.complete(lv1Str);
        String lv2 = String.valueOf(lv1 & 0xf);
        lv2 = PathMakerUtil.complete(lv2);
        return seprator + lv1Str + seprator + lv2 + seprator;
    }

    /**
     * 补齐3位长度
     * @param path
     * @return
     */
    private static  String complete(String path) {
        if(path.length()<=1)
            path="00"+path;
        if(path.length()<=2)
            path="0"+path;
        return path;
    }
}
